function ExcelExportHelper(reportVo, columns, variables) {

    this.HEADER_CELL_STYLE = ' style="text-align:center; font-weight:bold; background-color:#B3DCEF; font-family: Calibri; border-style:double; "';
    this.DATA_CELL_STYLE = ' style=" font-family:Calibri; font-weight:normal; text-align:left" ';
    this.TITLE_CELL_STYLE = ' style="text-align:center; font-family:Calibri; font-weight:bold; text-size: 14px; border-style:double; background-color:#81C4E4; "';
    this.DATA_CELL_NUMRIC_STYLE = ' style="text-align:center; font-family:Calibri; font-weight:normal; text-align:right;" ';
    this.VARIABLE_HEADER_STYLE = ' style="text-align:center; font-family:Calibri; background-color:#B3DCEF; " ';
    this.headerColor = '#F0F8FF';
    this.GROUP_CELL_STYLE = ' style="text-align:left; font-family:Calibri; background-color:#E6F3FA; font-weight:bold" ';
    this.GROUP_CELL_NUMRIC_STYLE = ' style="text-align:right; font-family:Calibri; background-color:#E6F3FA; font-weight:bold" ';

    this.reportVO = "";
    this.selectionsList = variables;
    this.width = "800";

    this.reportVo = reportVo;
    this.columns = columns;
    this.variables = variables;

    ExcelExportHelper.prototype.generateExcel = function () {
        if(reportVo !== undefined)
        {
            var title = this.printingTheTitle("Fire Protection Department KPI", this.TITLE_CELL_STYLE, 450);
            var variablesTable = this.printingTheVariables(this.selectionsList, this.VARIABLE_HEADER_STYLE, this.DATA_CELL_STYLE, 450);
            var columnsName = this.printingColumnsNames(columns, this.reportVo.columns, this.HEADER_CELL_STYLE, 450, reportVo.fullComponentsList);
            //   var columnsData = this.printingTheBody(this.reportVo.rows, columns, this.DATA_CELL_STYLE, 450);
            var columnsData = this.getGroupedList(reportVo.fullComponentsList, reportVo.rowsFull, this.GROUP_CELL_STYLE,
                this.DATA_CELL_STYLE, this.DATA_CELL_NUMRIC_STYLE, columns, 450, this.GROUP_CELL_NUMRIC_STYLE);
            var result = "<table width='900' border='1'>" + title + variablesTable + columnsName + columnsData + "</table>";
            return result;
        }
        else
        {
            alert('No data to be exported');
        }
        return '';

    }

    ExcelExportHelper.prototype.printingTheTitle = function (title, style, width) {
        var result = "";

        result += '<tr width="' + width + '"' + " >" +
            "<th colspan='3' " + style + ">" +  title +  "</th>"  +
            '</tr>';
        return result;
    }

    ExcelExportHelper.prototype.printingTheVariables = function (selectionList, headStyle, dataStyle, width) {
        var result = "";
        var gridColumnArray = [];
        result += '<tr width="' + width + '"' + " >" + "<th colspan='3' " + this.HEADER_CELL_STYLE + "> Variables </th>"  + "</tr>";
        for (var y = 0; y < selectionList.length; y++) {
            result += '<tr width="' + width + '"' + " >";
            result += "<th colspan='3' " + dataStyle + " >" +  selectionList[y].label  + ": " + getVariablesValues(selectionList[y].values) + "</th>";
            result += "</tr>";
        }

        return result;
    }

    function getVariablesValues(values) {
        var result = "";
        for (var x = 0; x < values.length; x++) {
            if (result != "")
                result += " ,";

            result += values[x];
        }
        return result;
    }


    ExcelExportHelper.prototype.printingColumnsNames = function (selectedColumns, columnsList, style, width, fullComponentsList) {
        var result = "";
        result += '<tr width=' + width + '>';
        //Set the tableheader data (retrieves information from the datagrid header

        for (var x = 0; x < selectedColumns.length; x++) {
            var isFound = false;
            var techName = '';
            for (var i = 0; i < columnsList.length; i++) {
                techName = columnsList[i]['techname'];
                if (selectedColumns[x] === techName) {

                    result += "<th " + style + ">" + columnsList[i]['caption'] + "</th>";
                    isFound = true;
                    break;
                }

                else if (columnsList[i].hasOwnProperty('columns')) {
                    for (var m = 0; m < columnsList[i]['columns'].length; m++) {
                        if (columnsList[i]['columns'][m]['techname'] === selectedColumns[x]) {
                            result += "<th " + style + ">" + columnsList[i]['columns'][m]['caption'] + "</th>";
                            isFound = true;
                            break;
                        }
                    }
                }
            }
            if(!isFound)
            {

                result += "<th " + style + ">" + 'Target' + "</th>";
                /*var isFound2 = false;
                for(var m = 0; m < columnsList.length; m++)
                {
                    if(columnsList[m]['techname'] === '4X82IUEA00P0UII7RDRDCHP46')
                    {
                        result += "<th " + style + ">" + columnsList[m]['caption'] + "</th>";
                        isFound2 = true;
                        break;
                    }

                }

                if(!isFound2)
                    result += "<th " + style + ">" + 'Target' + "</th>";*/

            }

        }


        result += "</tr>";
        console.log('printingColumnsNames() /n' + result);
        return result;
    }

    ExcelExportHelper.prototype.getGroupedList = function(groups, rows, groupStyle, rowStyle, rowStyleNumric, selectedColumns, width, groupStyleNumric) {
        var result="";
        for(var i = 0; i < groups.length; i++)
        {
            var text = (groups[i]['text'] === undefined)? '' :  groups[i]['text'];
            var target =  (groups[i]['target'] === undefined)? '' :  groups[i]['target'];
            var value =   (groups[i]['value'] === undefined)? '' :  groups[i]['value'];

            result += "<tr>";
            result += "<td " + groupStyle + ">" + text + "</td>";
            result += "<td " + groupStyleNumric + ">" + target + "</td>";
            result += "<td " + groupStyleNumric + ">" + value + "</td>";
            result += "</tr>";

            for(var x=0; x < rows.length; x++)
            {
                if(groups[i]['id'] == rows[x]['ZFIRCOMP'])
                {
                    // Get Cells for the selected columns
                    if(selectedColumns.length > 0 )
                    {
                        result += "<tr>";
                        for (var y = 0; y < selectedColumns.length; y++) {
                            var techName = selectedColumns[y];
                            var cellValue = "";

                            if (rows[x].hasOwnProperty(techName)) {
                                if(techName !== 'target')
                                    cellValue = rows[x][techName];
                            }


                            else {
                                for (var prop in rows[x]) {
                                    if (prop.indexOf(techName) > 0) {
                                        cellValue = rows[x][prop];
                                        break;
                                    }
                                }
                            }
                            if(y === 0)
                                result += "<td " + rowStyle + ">" + cellValue + " </td>";
                            else
                                result += "<td " + rowStyleNumric + ">" + cellValue + " </td>";

                        }
                        result += "</tr>";
                    }

                    // Get Cells for all columns
                    else
                    {
                        for (var prop in rows[x]) {
                            result += "<td " + rowStyle + ">" + data[prop] + " </td>";
                        }
                    }

                }
            }

        }
        return result;
    }

    ExcelExportHelper.prototype.openWindowWithPost = function(formID, htmlTable, fileName)
    {
        var f = document.getElementById(formID);
        f.htmltable.value = htmlTable;
        f.fileName.value = fileName;
        window.open('', 'TheWindow');
        f.submit();
    }
}